import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DeleteResult, Repository, UpdateResult } from 'typeorm';
import { Bk_Series } from './bk_series.entity';

@Injectable()
export class SeriesService {
    constructor(
        @InjectRepository(Bk_Series)
        private readonly seriesRepository: Repository<Bk_Series>
    ) { }

    async add(series: { series_name: string }): Promise<Bk_Series> {
        return await this.seriesRepository.save(series);
    }
    async delete(id: number): Promise<DeleteResult> {
        return await this.seriesRepository.delete(id);
    }
    async update(id: number, series: { series_name: string }): Promise<UpdateResult> {
        return await this.seriesRepository.update(id, series);
    }

    async findAll(query: any): Promise<[Bk_Series[],number]> {
        return await this.seriesRepository.findAndCount({ order: { id: "ASC" }, skip: query.skip, take: query.take });
    }

}